;  Starting point of the kernel
;  Interrupts are not enabled yet.
[BITS 32]
global start
start:
	mov	esp, _sys_stack				; Set up the stack
	jmp stub						; Jump to the rest of code
	
; This part of header needs to 4 Bit aligned
ALIGN 4
mboot:
	; Some macro's to make the code a bit further look cleaner
	MULTIBOOT_PAGE_ALIGN	equ 1<<0
    MULTIBOOT_MEMORY_INFO	equ 1<<1
    MULTIBOOT_AOUT_KLUDGE	equ 1<<16
    MULTIBOOT_HEADER_MAGIC	equ 0x1BADB002
    MULTIBOOT_HEADER_FLAGS	equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE
    MULTIBOOT_CHECKSUM		equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
	EXTERN code, bss, end

	; Grub multiboot header
	dd MULTIBOOT_HEADER_MAGIC
    dd MULTIBOOT_HEADER_FLAGS
    dd MULTIBOOT_CHECKSUM
	
	dd mboot
    dd code
    dd bss
    dd end
    dd start
	
; Rest of the code
; Infinite loop
stub:
	extern _main
	call _main
	jmp $
	
SECTION .bss
	resb 8192						; Reserve 8 Kb of memory
_sys_stack:
